package com.jin10.util;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.jin10.bean.DingParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author raofy
 * @date 2022-02-09 17:39
 * @desc 钉钉发送通知
 */
public class DingTalk {

    private final static Logger log = LoggerFactory.getLogger(DingTalk.class);

    /**
     * 发送整合后段落到钉钉群
     *
     * @param message
     */
    public static void sendToGroup(String message) {
        DingParams params = new DingParams();
        params.setMsgtype("text");
        DingParams.TextBean text = new DingParams.TextBean();
        text.setContent("{文章}" + "\n" + message);
        params.setText(text);
        try {
            HttpResponse execute = HttpRequest.post("https://oapi.dingtalk.com/robot/send?access_token=554587dacb2aa703f2433b9c0288a05a2ed8085e7b0f03aee900d4bc40fe3e2c").body(JSON.toJSONString(params)).execute();
            if (execute.getStatus() == 0) {
                log.info("钉钉提醒成功！！");
            }
        } catch (Exception e) {
            log.info("钉钉提醒失败，" + e.getMessage());
        }
    }
}
